#include "BinIns.h"
#include <cstdint>
#include <cstdlib>
#include <cstring>
/*定义宏来模拟指令的解码*/
/*IR为指令寄存器*/
#define REG0 (IR >> 16 & 0xff)
#define REG1 (IR >> 8 & 0xff)
#define REG2 (IR & 0xff)
#define IMMEDIATE (IR >> 8 & 0xff)
#define ADDRESS (IR >> 16 & 0xff)
#define PORT (IR & 0xff)
#define OPCODE ((IR >> 24) & 0xff)
namespace simu_kernel
{

struct statement
{
  unsigned short overflow; /*判定溢出1为溢出，0为正常*/
  unsigned short compare;  /*比较大小，1为真，0为假*/
  unsigned short reserve;  /*无实际意义*/
};
extern statement state;
/*记录当前的pos，GR，state*/
struct list
{
  statement s;      /*记录字段结构state*/
  short G[8];       /*记录寄存器值*/
  unsigned long pt; /*记录当前执行到的行数pos*/
  list *next;
};
extern list *head, *p, *q;
/*PC 指令计数器，用来存放下条指令的内存地址*/
extern uint32_t *pc, op[300], IR;
extern uint8_t data[240];

extern uint16_t GR[8];     /*8个通用寄存器*/
extern int pos;            /*记录程序运行的位置*/
extern uint8_t ss[100], x; /*ss为堆栈，x为位置*/

extern char inout;
extern bool out, in;

extern int HLT();
extern int JMP();
extern int CJMP();
extern int OJMP();
extern int CALL();
extern int RET();
extern int PUSH();
extern int POP();
extern int LOADB();
extern int LOADW();
extern int STOREB();
extern int STOREW();
extern int LOADI();
extern int NOP();
extern int IN();
extern int OUT();
extern int ADD();
extern int ADDI();
extern int SUB();
extern int SUBI();
extern int MUL();
extern int DIV();
extern int AND();
extern int OR();
extern int NOR();
extern int NOTB();
extern int SAL();
extern int SAR();
extern int EQU();
extern int LT();
extern int LTE();
extern int NOTC();

extern int (*ops[])(void);
} // namespace simu_kernel
